<template>
	<div class="zh-header clear"
		v-loading="loading.status"
		:element-loading-text="loading.txt"
		v-loading.fullscreen.lock="loading.full">
		<div class="zh-h-left fl">
			<a style="display: block;cursor: pointer;"  @click="goHome('/home')">
				<span class="zh-head-portrait">
					<img :src="sysLogo" alt="">
				</span>
				<span class="zh-head-h2"> {{$store.getters.leftMenuNav.txtName}}</span>
			</a>
		</div>

		<div class="zh-h-right fr clear">
			<div class="zh-cutover fl" v-popover:cutover v-if="switching">
				<a href="javascript:void(0)">切换子系统</a>
				<el-popover
					ref="cutover"
				  	placement="bottom"
				  	v-model="cutover"
				  	trigger="hover"
				  	popper-class="zh-drop">
					<ul class="zh-drop-down">
							<template v-for="item in selectNav">
									<router-link :index="item.name" :key="item.name" :to="`/${item.path}/${item.children[0].path}/${item.children[0].children[0].path}`" tag="li">
											<div :class="$route.path.split('/')[1] ==  item.path ? 'active' : ''">
													{{item.txtName}}
													<i class="el-icon-circle-check" v-if="$route.path.split('/')[1] == item.path "></i>
											</div>
									</router-link>
							</template>
					</ul>
				</el-popover>
			</div>

			<div class="fr" v-popover:popover>
				<span class="zh-head-portrait">
					<img :src="BASE_URL+$store.getters.userInfo.avatar_path" alt="">
				</span>
				<span class="zh-user-info">
					<span>{{$store.getters.userInfo.number}}</span>
					<span>{{$store.getters.userInfo.name}}</span>
				</span>
				<el-popover
					ref="popover"
				  	placement="bottom"
				  	v-model="visible"
				  	trigger="hover"
				  	popper-class="zh-drop">
					<ul class="zh-drop-down">
					  	<li @click="pageHome()">网站首页</li>
					  	<li v-show="isShowPersonal" @click="backPersonal()">个人中心</li>
					  	<li @click="loginOut()">退出账号</li>
					</ul>
				</el-popover>
			</div>
		</div>
	</div>
</template>
<script>
import { userInfo } from '../../store/getters';
	export default {
	    data() {
	      	return {
						isShowPersonal: sessionStorage.getItem('CheckSchoolAppCode') === JSON.parse(sessionStorage.getItem('user_info_str')).app_code,
				// 加载数据时显示动效
	      		loading:{
	      			status:false,
	      			txt:'正在退出系统...',
	      			full:false
				},
				// poper 参数 
	        	visible: false,
	        	cutover: false,
	        	switching: true,
				h1: false,
				// 用户信息
				userInfo: deep_clone( this.$store.getters.userInfo ),
	            systemLogoSrc: {
					'portal' : '/static/image/management/portal.svg',
					'user' : '/static/image/management/user.svg',
					'resources' : '/static/image/management/resources.svg',
					'teaching' :  '/static/image/management/teaching.svg',
                    'affairs' : '/static/image/management/affairs.svg',
                    'life': '/static/image/management/life.svg',
					'system':'/static/image/management/system.svg',
				},
				sysLogo:'/static/image/head.png',

	      	};
	    },
	    created(){
            this.sysLogo = this.systemLogoSrc[this.$route.fullPath.split('/')[1]]
        },
        computed: {
            // 菜单路由-此处的路由路径是需要层层的拼接得到的，不满足拼接成完整路径的项就过滤掉
            selectNav(){
                let data = deep_clone( this.$router.options.routes[3].children );
                return data.filter(x => { return x.children.length > 0 && x.children[0].children.length > 0});
            }
        },
	    methods: {
			goHome(link) {
				this.$router.push(link);
			},
        	pageHome(){
        		 window.location.href = sessionStorage.getItem('host_addr');
        	},
        	backPersonal() {
        		let manage_url = sessionStorage.getItem( 'host_addr' )
                let redirect_params = sessionStorage.getItem( 'redirect_params' )
        		window.location.href = manage_url + '/personal' + redirect_params
        	},
			loginOut(){
                this.$store.commit('SET_OUTLOGIN', true);
                // this.loading.txt = '正在退出系统...';
                // this.loading.full = true;
                                
                // if (JSON.parse(sessionStorage.getItem('user_info_str')).logout_url) {
                //     this.loading.txt = '退出成功...';
                //     this.loading.full = true;
                //     let user_info_str = JSON.parse(sessionStorage.getItem('user_info_str'));

                //     setTimeout(() => {
                //         sessionStorage.clear();
                //         // localStorage.clear();
                //         window.location.href = user_info_str.logout_url;
                //     }, 500)
                // } else {
                //     let success = ( data => {
                //         this.loading.txt = '退出成功...';
                //         this.loading.full = true;
                //         let host_addr = sessionStorage.getItem('host_addr');

                //         setTimeout(() => {
                //             sessionStorage.clear();
                //             // localStorage.clear();
                //             window.location.href = host_addr;
                //         }, 1000)
                //     });
                //     let fail = ( data => {
                //         this.$message.error(data.msg)
                //         this.loading.txt = data.msg;
                //         this.loading.full = true

                //         setTimeout(() => {
                //             this.loading.status =  false;
                //             this.loading.full = false
                //         }, 1000)
                //     });
                //     this.$ajax.delete('api/login/new_login',{params:{},func:{success:success,fail:fail}})
                // }
			}
        },
		watch:{
			$route(){
				this.sysLogo = this.systemLogoSrc[this.$route.fullPath.split('/')[1]]
			},
		}
	}
</script>
